<template>
  <div id="NewsInformation">
    <router-view></router-view>
      <div class="container">
      <!-- <div class="container text-center">
                <h3>行业新闻</h3>
                <p style="color:#b2b2b2">Company News</p>
            </div> -->
      <!-- <div class="nav container text-center">
                <a href="#" class="active">公司新闻</a>
                <a href="#">行业动态</a>
            </div> -->
      <div v-if="lei_arr.length">
        二级分类:
        <van-tag
          v-for="i in lei_arr"
          class="cus ml"
          @click="go_lei(i.id)"
          :key="i.id"
          type="primary"
          >{{ i.gname }}</van-tag
        >
      </div>
      <van-divider />

      <van-cell-group>
        <van-cell
          v-for="(i, k) in cp_list"
          :key="k"
          :title="i.pname"
          :label="i.indir"
          @click="go_new(i)"
          :value="timeTrans(i.createtime)"
        />     
      </van-cell-group>
      <div style="height: 20px"></div>
    </div>
   
    
  </div>
</template>
<script>
import { WOW } from "wowjs";
export default {
  name: "xiang",
  data() {
    return {
      l_id:'',
      lei_arr: [],
      new_arr: [],
      newsList: [],
      pname: "",
      cp_list: [],
    };
  },
  mounted() {
    var wow = new WOW();
    wow.init();
    let info = this.$route.query.i;
     
     let ff=  JSON.parse(decodeURIComponent(info));
    
    console.log("info:", ff);

    this.l_id=ff.id;
     let v=this;
    //   let dd=localStorage.getItem('l_id');
    // if(info){
    //    localStorage.setItem('l_id',info.id);
    // }else{
    //   if(dd){
    //      v.l_id=dd;
    //   };
    // }
     
   
      

    // if(dd){
    //   this.l_id=dd;
    // };
    this.get_lei();
      this.get_cp();
   
  },
  methods: {
    timeTrans(date) {
      var date = new Date(date * 1000);
      var Y = date.getFullYear() + "-";
      var M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      var D =
        (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
      var h =
        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
      var m =
        (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
        ":";
      var s =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      return Y + M + D + h + m + s;
    },
    get_lei(id) {
      let data = {
        pid: this.l_id,
      };
      let v = this;
      this.http.post("/products/getproductlei", data).then((res) => {
        console.log("lei:", res);
        if (res.data.data) {
          v.lei_arr = res.data.data;
        } else {
          // v.lei_arr=[]
        }
      });
    },

    get_cp(id) {
      console.log("idid:", id);
      console.log('55:',this.l_id);
      let v = this;
      let data = {
        page: 1, 
        pagesize: 100,
        fenlei: this.l_id,
        pname: this.pname,
      };
      this.http.post("/products/getproducts", data).then((res) => {
        console.log("res3:", res);
        if (res.data.data) {
          v.cp_list = res.data.data;
        } else {
          v.cp_list = [];
        }
      });
    },

    go_new(e) {
      this.$router.push({ path: "xiang2", query: { info: e } });
    },
    get_list() {
      let v = this;
      this.http.post("/news/getnewsmsg").then((res) => {
        console.log("新闻:", res);
        if (res.data.data) {
          v.new_arr = res.data.data;
        }
      });
    },
  },
};
</script>
<style scoped>
.nav {
  margin: 20px 0;
}
.nav > a {
  display: inline-block;
  text-decoration: none;
  width: 120px;
  height: 45px;
  line-height: 45px;
  color: #333;
  border: 1px solid #333;
}
.nav > a.active {
  color: #1e73be;
  border-color: #1e73be;
}
.nav > a:hover {
  color: #1e73be;
  border-color: #1e73be;
}
.news-container {
  overflow: hidden;
  margin-bottom: 0;
}
.news-container > li {
  width: 55.6%;
  height: 120px;
  float: left;
  color: #333;
  text-align: right;
  border-left: 1px solid transparent;
  border-right: 1px solid transparent;
}
.news-container > li:hover {
  color: #1e73be;
  border: 1px solid #1e73be;
  cursor: pointer;
}
.news-container > li:nth-of-type(2n) {
  float: right;
  text-align: left;
}
.news-container > li > .content {
  width: 60%;
  float: left;
  padding: 20px 0;
}
.news-container > li > .time {
  width: 20%;
  float: left;
  padding: 10px 0;
}
.news-container > li > .time > p {
  font-size: 30px;
  margin: 5px 0;
}
.news-container > li > .circle {
  width: 20%;
  height: 100%;
  float: left;
  position: relative;
}
.news-container > li > .circle > img {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: auto;
  width: 20px;
  height: 20px;
}
.news-container > li > .circle > i {
  display: block;
  width: 1px;
  height: 100%;
  background: #707070;
}
.news-container > li:nth-of-type(2n) > .content {
  float: right;
}
.news-container > li:nth-of-type(2n) > .time {
  float: right;
}
.news-container > li:nth-of-type(2n) > .circle {
  float: right;
}
.news-container > li:nth-of-type(1) > .circle > i {
  height: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
}
.more {
  font-size: 25px;
  color: #707070;
}
.more > i {
  cursor: pointer;
}
@media screen and (max-width: 767px) {
  .news-container > li {
    width: 100%;
  }
  .news-container > li > .content {
    width: 70%;
    text-align: left;
    float: right;
  }
  .news-container > li > .time {
    width: 30%;
    text-align: left;
    float: right;
  }
  .news-container > li > .circle {
    display: none;
  }
}
</style>

